<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class ResetPasswordConsole extends Command
{
    /**
     * The name and signature of the console command.
     * @var string
     */
    protected $signature = 'ResetPasswordConsole';

    /**
     * The console command description.
     * @var string
     */
    protected $description = '重置后台登录密码';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $user = User::first();

        if (!$user) {
            $this->error('账号不存在');
            return;
        }

        $newPassword = Str::random(10);
        $user->password = Hash::make($newPassword);
        $user->save();

        $this->info('用户名：' . $user->username);
        $this->info('新密码：' . $newPassword);
    }

}
